﻿using MODEL;
using SysHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace SysController
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
         
        public ActionResult GetMenu()
        {
            var list = SysHelper.OperateContext.CurrentContext.BllSession.ISystemMenu_BLL.GetListByWhere(s => s.IsDel == false);
            var listP = list.Where(s => s.PSystemMenuID == 0).ToList();
            List<MenuModel> ls = new List<MenuModel>();
            foreach (var item in listP)
            {
                MenuModel model = new MenuModel()
                {
                    Menu = item,
                    ChildMenu = list.Where(s => s.PSystemMenuID == item.SystemMenuID).ToList()
                };
                ls.Add(model);
            } 
            ViewData["Menu"] = ls;
            return PartialView("MenuPartial");
        }

        public ActionResult ItemOpreation()
        {
            return PartialView();
        }

        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(LoginUser model)
        {
            if (!ModelState.IsValid)
            {
                return OperateContext.CurrentContext.RedirectAjax("Err", "登录无效", null, "");
            }
            if (model.UserName == "valeb" && model.UserPass == "123")
            {
                return OperateContext.CurrentContext.RedirectAjax("OK", "登录成功", null, "/Client/Home/Index/");
            }
            else
            {
                return OperateContext.CurrentContext.RedirectAjax("Error", "登录失败", null, "");
            }
        }
    }
}
